package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.result.Result;

import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.TrackInfoVo;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album/trackInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class TrackInfoApiController {

    @Autowired
    private TrackInfoService trackInfoService;

    /**
     * 音频上传
     *
     * @param file
     * @return
     */
    @PostMapping(value = "/uploadTrack")
    public Result uploadTrack(@RequestParam MultipartFile file) {
        return Result.ok(trackInfoService.uploadTrack(file));
    }

    /**
     * 文件上传
     */
    @PostMapping(value = "/saveTrackInfo")
    public Result saveTrackInfo(@RequestBody TrackInfoVo trackInfoVo) {
        trackInfoService.saveTrackInfo(trackInfoVo);
        return Result.ok();
    }

    /**
     * 音频分页
     */
    @PostMapping(value = "/findUserTrackPage/{page}/{size}")
    public Result findUserTrackPage(@PathVariable(value = "page") Integer page,
                                    @PathVariable(value = "size") Integer size,
                                    @RequestBody TrackInfoQuery trackInfoQuery) {
        return Result.ok(trackInfoService.findUserTrackPage(page, size, trackInfoQuery));
    }

    /**
     * 删除
     */
    @DeleteMapping(value = "/removeTrackInfo/{trackId}")
    public Result removeTrackInfo(@PathVariable(value = "trackId") Long trackId) {
        trackInfoService.removeTrackInfo(trackId);
        return Result.ok();
    }

    /**
     * 数据回显
     */
    @GetMapping(value = "/getTrackInfo/{trackId}")
    public Result getTrackInfo(@PathVariable(value = "trackId") Long trackId) {
        return Result.ok(trackInfoService.getTrackInfo(trackId));
    }

    /**
     * 提交修改后数据
     */
    @PutMapping(value = "/updateTrackInfo/{trackId}")
    public Result updateTrackInfo(@PathVariable(value = "trackId") Long trackId,
                                  @RequestBody TrackInfoVo trackInfoVo) {
        trackInfoService.updateTrackInfo(trackId,trackInfoVo);
        return Result.ok();
    }

}

